#ifndef __RESOURCE_MANAGER_H__
#define __RESOURCE_MANAGER_H__

#include "../Header.h"
#include "Resource.h"
#include <vector>
#include <list>

template <class ResourceType>
class ResourceGroup
{
private:
	std::list<ResourceType> *m_HandleList;
	void(*m_CreateResource)(ResourceType **resource, char *name, char *path);
public:
	ResourceGroup(void(*CreateResource)(ResourceType **resource, char *name, char *path) = 0)
	{
		m_List.resize(0);
		m_HandleList = new std::list<ResourceType>();
		m_CreateResource = CreateResource;
	}
	~ResourceGroup()
	{
		m_List.clear();
		m_HandleList->clear();
		SAFE_DELETE(m_HandleList);
	}

	ResourceType *Add(char *name, char *path)
	{
		//Return NULL if resource direc not true
		if (name == 0 || path == 0 || m_HandleList == 0)
			return 0;

		//if element is exist, return pointer to it
		ResourceType *element = GetElement(name, path);
		if (element != 0)
		{
			element.IncRef();
			return element;
		}

		//Create resource
		ResourceType *resource = 0;
		if (m_CreateResource != 0)
		{
			m_CreateResource(&resource, name, path);
		}
		else
		{
			resource = new ResourceType(name, path);
		}

		//Add resource to manager list
		m_List.push_back(resource);
		m_HandleList->push_back(resource);

		return resource;
	}

	void Remove(ResourceType **resource)
	{
		if (*resource == 0 || m_HandleList == 0)
			return;

		(*resource)->DecRef();

		if ((*resource)->GetRefCount() == 0)
		{
			m_HandleList->remove(resource);
		}
	}

	void EmptyList()
	{
		if (m_HandleList != 0)
			m_HandleList->empty();
	}

	std::list<ResourceType> *GetList()
	{
		return m_HandleList;
	}

	ResourceType *GetElement(char *name, char *path)
	{
		if (m_HandleList == 0 || name == 0 || path == 0)
			return 0;

		if (m_HandleList->begin() == 0)
			return 0;

		m_HandleList->
	}
};

#endif